package io.ex.web

import io.vertx.core.ioc.B
import io.vertx.core.ioc.VertxComponent
import io.vertx.core.spi.resolver.ResolverProvider.DISABLE_DNS_RESOLVER_PROP_NAME
import io.vertx.ext.web.Router
import io.vertx.kotlin.coroutines.CoroutineVerticle
import io.vertx.kotlin.pgclient.queryAwait
import io.vertx.pgclient.PgPool
import kotlinx.coroutines.launch


class PersonService:VertxComponent {
    private lateinit var pgPool: PgPool
    override fun init(b: B) {
        pgPool = b.pgPool()
    }
    suspend fun queryNameById(id:Int):String? {
        val rs = pgPool.queryAwait("select name from Person where id=$id").toList()
        if(rs.isEmpty()) {
            return null
        }
        return rs[0].getString(0)
    }
}
class DemoVerticle:CoroutineVerticle() {

    override suspend fun start() {
        val server = vertx.createHttpServer()
        val router = Router.router(vertx)
        val httpClient = vertx.createHttpClient()
        router.route().handler{
            launch {
                val des = "http://www.baidu.com"




            }
        }
    }


}

fun main() {
    System.setProperty(DISABLE_DNS_RESOLVER_PROP_NAME,"true")
}